{#**
 * 2007-2020 PrestaShop SA and Contributors
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * https://opensource.org/licenses/OSL-3.0
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@prestashop.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
 * versions in the future. If you wish to customize PrestaShop for your
 * needs please refer to https://www.prestashop.com for more information.
 *
 * @author    PrestaShop SA <contact@prestashop.com>
 * @copyright 2007-2020 PrestaShop SA and Contributors
 * @license   https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
 * International Registered Trademark & Property of PrestaShop SA
 *#}

{% extends '@WebProfiler/Profiler/layout.html.twig' %}

{% block toolbar %}
  {% set icon %}
    {{ include('@WebProfiler/Icon/request.svg') }}
    <span class="sf-toolbar-value">Commands / Queries</span>
  {% endset %}

  {% set text %}
    <div class="sf-toolbar-info-piece">
      <div class="sf-toolbar-info-piece">
        <b class="sf-toolbar-ajax-info">Commands / Queries</b>
      </div>
      <div class="sf-toolbar-info-piece">
        <b>Commands</b>
        {% set commandsCount = collector.executedCommands|length %}
        <span class="sf-toolbar-status sf-toolbar-status-{% if commandsCount > 0 %}green{% else %}red{% endif %}">
          {{ commandsCount }}
        </span>
      </div>
      <div class="sf-toolbar-info-piece">
        <b>Queries</b>
        {% set queriesCount = collector.executedQueries|length %}
        <span class="sf-toolbar-status sf-toolbar-status-{% if queriesCount > 0 %}green{% else %}red{% endif %}">
          {{ queriesCount }}
        </span>
      </div>
    </div>
  {% endset %}

  {{ include('@WebProfiler/Profiler/toolbar_item.html.twig', { 'link': true }) }}
{% endblock %}

{% block menu %}
  <span class="label">
    <span class="icon">{{ include('@WebProfiler/Icon/request.svg') }}</span>
    <strong>Commands / Queries</strong>
  </span>
{% endblock %}

{% block panel %}
  <h2>Commands / Queries</h2>

  <div class="sf-toolbar-info-piece">
    <table class="sf-toolbar-ajax-requests">
      <thead>
        <tr>
          <th>Command</th>
          <th>Command handler</th>
        </tr>
      </thead>
      <tbody class="sf-toolbar-ajax-request-list">
        {% if collector.executedCommands is not empty %}
          {% for command in collector.executedCommands %}
            <tr>
              <td>{{ command.command }}</td>
              <td>{{ command.command_handler }}</td>
            </tr>
          {% endfor %}
        {% else %}
          <tr>
            <td colspan="2">No Commands where executed during request.</td>
          </tr>
        {% endif %}
      </tbody>
    </table>

    <table class="sf-toolbar-ajax-requests">
      <thead>
        <tr>
          <th>Query</th>
          <th>Query Handler</th>
        </tr>
      </thead>
      <tbody class="sf-toolbar-ajax-request-list">
      {% if collector.executedQueries is not empty %}
        {% for query in collector.executedQueries %}
          <tr>
            <td>{{ query.query }}</td>
            <td>{{ query.query_handler }}</td>
          </tr>
        {% endfor %}
      {% else %}
        <tr>
          <td colspan="2">No Queries where executed during request.</td>
        </tr>
      {% endif %}
      </tbody>
    </table>
  </div>
{% endblock %}
